package com.apkcore.bl;

public class _65有效数字 {

    public static void main(String[] args) {
        System.out.println(new _65有效数字().isNumber(".2e81"));
    }

    private static final int S0 = 1;// 初始状态
    private static final int S1 = 2;//符号
    private static final int S2 = 4;//整数
    private static final int S3 = 8;//左无整数小数点
    private static final int S4 = 16;//小数
    private static final int S5 = 32;//指数e
    private static final int S6 = 64;//指数符号
    private static final int S7 = 128;//有效数字

    public boolean isNumber(String s) {
        if (s == null || s.length() == 0) {
            return false;
        }
        char[] chars = s.toCharArray();
        int state = S0;
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            switch (state) {
                case S0:
                    if (c == '+' || c == '-') {
                        state = S1;
                    } else if (c == '.') {
                        state = S3;
                    } else if (Character.isDigit(c)) {
                        state = S2;
                    } else {
                        return false;
                    }
                    break;
                case S1:
                    if (Character.isDigit(c)) {
                        state = S2;
                    } else if (c == '.') {
                        state = S3;
                    } else {
                        return false;
                    }
                    break;
                case S2:
                    if (Character.isDigit(c)) {
                        state = S2;
                    } else if (c == '.') {
                        state = S4;
                    } else if (c == 'e' || c == 'E') {
                        state = S5;
                    } else {
                        return false;
                    }
                    break;
                case S3:
                    if (Character.isDigit(c)) {
                        state = S4;
                    } else {
                        return false;
                    }
                    break;
                case S4:
                    if (Character.isDigit(c)) {
                        state = S4;
                    } else if (c == 'e' || c == 'E') {
                        state = S5;
                    } else {
                        return false;
                    }
                    break;
                case S5:
                    if (c == '+' || c == '-') {
                        state = S6;
                    } else if (Character.isDigit(c)) {
                        state = S7;
                    } else {
                        return false;
                    }
                    break;
                case S6:
                    if (Character.isDigit(c)) {
                        state = S7;
                    } else {
                        return false;
                    }
                    break;
                case S7:
                    if (Character.isDigit(c)) {
//                        state = S7;
                    } else {
                        return false;
                    }
                    break;
                default:
                    return false;
            }
        }
        return state == S2 || state == S4 || state == S7;
    }
}
